package com.jiyi.activity.datainput.sm;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jiyi.activity.datainput.DIBaseMorePicActivity;
import com.jiyi.bean.SingleImageBean;
import com.jiyi.bean.datainput.new_input.BaseCheck;
import com.jiyi.bean.datainput.new_input.FireManageBean;
import com.jiyi.exception.SampleProgressObserver;
import com.jiyi.inteface.DownloadPicOverInterface;
import com.jiyi.retrofit.HttpMethods;
import com.jiyi.widget.NoScrollGridView;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.base.AppMediaType;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.MultipartBody;

/**
 * Created by Administrator on 2018/3/22.
 */

public class BuildSpaceManageActivity extends DIBaseMorePicActivity implements DownloadPicOverInterface {
    /* 头部 */
    @BindView(R.id.tvBack)
    TextView tvBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSearch)
    TextView tvSearch;


    @BindView(R.id.rbDutyYes)
    RadioButton rbDutyYes;
    @BindView(R.id.rbDutyNo)
    RadioButton rbDutyNo;
    @BindView(R.id.rgDutyIsOK)
    RadioGroup rgDutyIsOK;
    @BindView(R.id.etDutyProblem)
    EditText etDutyProblem;
    @BindView(R.id.etDutyMeasure)
    EditText etDutyMeasure;
    @BindView(R.id.rbEachDutyYes)
    RadioButton rbEachDutyYes;
    @BindView(R.id.rbEachDutyNo)
    RadioButton rbEachDutyNo;
    @BindView(R.id.rgEachDutyIsOK)
    RadioGroup rgEachDutyIsOK;
    @BindView(R.id.etEachDutyProblem)
    EditText etEachDutyProblem;
    @BindView(R.id.etEachDutyMeasure)
    EditText etEachDutyMeasure;
    @BindView(R.id.rbSafeCheckYes)
    RadioButton rbSafeCheckYes;
    @BindView(R.id.rbSafeCheckNo)
    RadioButton rbSafeCheckNo;
    @BindView(R.id.rgSafeCheckIsOK)
    RadioGroup rgSafeCheckIsOK;
    @BindView(R.id.etSafeCheckProblem)
    EditText etSafeCheckProblem;
    @BindView(R.id.etSafeCheckMeasure)
    EditText etSafeCheckMeasure;
    @BindView(R.id.rbDoorIsViolationYes)
    RadioButton rbDoorIsViolationYes;
    @BindView(R.id.rbDoorIsViolationNo)
    RadioButton rbDoorIsViolationNo;
    @BindView(R.id.rgDoorIsViolation)
    RadioGroup rgDoorIsViolation;
    @BindView(R.id.etDoorIsViolationProblem)
    EditText etDoorIsViolationProblem;
    @BindView(R.id.etDoorIsViolationMeasure)
    EditText etDoorIsViolationMeasure;
    @BindView(R.id.rbCertificateYes)
    RadioButton rbCertificateYes;
    @BindView(R.id.rbCertificateNo)
    RadioButton rbCertificateNo;
    @BindView(R.id.rgHasCertificate)
    RadioGroup rgHasCertificate;
    @BindView(R.id.etCertificateProblem)
    EditText etCertificateProblem;
    @BindView(R.id.etCertificateMeasure)
    EditText etCertificateMeasure;
    @BindView(R.id.rbTrainYes)
    RadioButton rbTrainYes;
    @BindView(R.id.rbTrainNo)
    RadioButton rbTrainNo;
    @BindView(R.id.rgHasTrain)
    RadioGroup rgHasTrain;
    @BindView(R.id.etTrainProblem)
    EditText etTrainProblem;
    @BindView(R.id.etTrainMeasure)
    EditText etTrainMeasure;
    @BindView(R.id.rbFireStationYes)
    RadioButton rbFireStationYes;
    @BindView(R.id.rbFireStationNo)
    RadioButton rbFireStationNo;
    @BindView(R.id.rgHasFireStation)
    RadioGroup rgHasFireStation;
    @BindView(R.id.etFireStationProblem)
    EditText etFireStationProblem;
    @BindView(R.id.etFireStationMeasure)
    EditText etFireStationMeasure;
    @BindView(R.id.rbManageYes)
    RadioButton rbManageYes;
    @BindView(R.id.rbManageNo)
    RadioButton rbManageNo;
    @BindView(R.id.rgHasManage)
    RadioGroup rgHasManage;
    @BindView(R.id.etManageProblem)
    EditText etManageProblem;
    @BindView(R.id.etManageMeasure)
    EditText etManageMeasure;
    @BindView(R.id.rbMaintenanceUnitYes)
    RadioButton rbMaintenanceUnitYes;
    @BindView(R.id.rbMaintenanceUnitNo)
    RadioButton rbMaintenanceUnitNo;
    @BindView(R.id.rbMaintenanceUnitNoInvolving)
    RadioButton rbMaintenanceUnitNoInvolving;
    @BindView(R.id.rgHasMaintenanceUnit)
    RadioGroup rgHasMaintenanceUnit;
    @BindView(R.id.etMaintenanceUnit)
    EditText etMaintenanceUnit;
    @BindView(R.id.etMaintenanceUnitProblem)
    EditText etMaintenanceUnitProblem;
    @BindView(R.id.etMaintenanceUnitMeasure)
    EditText etMaintenanceUnitMeasure;
    @BindView(R.id.rbDailyMaintenanceYes)
    RadioButton rbDailyMaintenanceYes;
    @BindView(R.id.rbDailyMaintenanceNo)
    RadioButton rbDailyMaintenanceNo;
    @BindView(R.id.rgHasDailyMaintenance)
    RadioGroup rgHasDailyMaintenance;
    @BindView(R.id.etDailyMaintenanceProblem)
    EditText etDailyMaintenanceProblem;
    @BindView(R.id.etDailyMaintenanceMeasure)
    EditText etDailyMaintenanceMeasure;
    @BindView(R.id.rbGuardianshipYes)
    RadioButton rbGuardianshipYes;
    @BindView(R.id.rbGuardianshipNo)
    RadioButton rbGuardianshipNo;
    @BindView(R.id.rgHasGuardianship)
    RadioGroup rgHasGuardianship;
    @BindView(R.id.etGuardianshipProblem)
    EditText etGuardianshipProblem;
    @BindView(R.id.etGuardianshipMeasure)
    EditText etGuardianshipMeasure;
    @BindView(R.id.rbRometeManageYes)
    RadioButton rbRometeManageYes;
    @BindView(R.id.rbRometeManageNo)
    RadioButton rbRometeManageNo;
    @BindView(R.id.rgHasRometeManage)
    RadioGroup rgHasRometeManage;
    @BindView(R.id.etRometeManageProblem)
    EditText etRometeManageProblem;
    @BindView(R.id.etRometeManageMeasure)
    EditText etRometeManageMeasure;

    int mDutyIsOK, mEachDutyIsOK, mSafeCheckIsOK, mDoorIsViolation, mHasCertificate, mHasTrain, mHasFireStation, mHasManage, mHasMaintenanceUnit, mHasDailyMaintenance, mHasGuardianship, mHasRometeManage;
    String build_id;
    @BindView(R.id.gvDuty)
    NoScrollGridView gvDuty;
    @BindView(R.id.gvEachDuty)
    NoScrollGridView gvEachDuty;
    @BindView(R.id.gvSafeCheck)
    NoScrollGridView gvSafeCheck;
    @BindView(R.id.gvDoorIsViolation)
    NoScrollGridView gvDoorIsViolation;
    @BindView(R.id.gvCertificate)
    NoScrollGridView gvCertificate;
    @BindView(R.id.gvTrain)
    NoScrollGridView gvTrain;
    @BindView(R.id.gvFireStation)
    NoScrollGridView gvFireStation;
    @BindView(R.id.gvManage)
    NoScrollGridView gvManage;
    @BindView(R.id.gvMaintenanceUnit)
    NoScrollGridView gvMaintenanceUnit;
    @BindView(R.id.gvDailyMaintenance)
    NoScrollGridView gvDailyMaintenance;
    @BindView(R.id.gvGuardianship)
    NoScrollGridView gvGuardianship;
    @BindView(R.id.gvRometeManage)
    NoScrollGridView gvRometeManage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_build_space_manage);
        ButterKnife.bind(this);
        init();
    }

    public void init() {
        getIntentData();
        setTop();
        setViewStatus();
        getData();
        super.setDownloadPicOverInterface(this);
    }

    private void getIntentData() {
        build_id = getIntent().getStringExtra("build_no");
        if (TextUtils.isEmpty(build_id))
            build_id = "";
    }

    private void setTop() {
        tvTitle.setText("消防安全管理方面");
        tvSearch.setCompoundDrawables(null, null, null, null);
        tvSearch.setText("保存");
    }

    public void setViewStatus() {
        rgDutyIsOK.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbDutyYes) {
                    mDutyIsOK = 1;
                } else {
                    mDutyIsOK = 0;
                }
            }
        });

        rgEachDutyIsOK.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbEachDutyYes) {
                    mEachDutyIsOK = 1;
                } else {
                    mEachDutyIsOK = 0;
                }
            }
        });

        rgSafeCheckIsOK.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbSafeCheckYes) {
                    mSafeCheckIsOK = 1;
                } else {
                    mSafeCheckIsOK = 0;
                }
            }
        });

        rgDoorIsViolation.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbDoorIsViolationYes) {
                    mDoorIsViolation = 1;
                } else {
                    mDoorIsViolation = 0;
                }
            }
        });

        rgHasCertificate.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbCertificateYes) {
                    mHasCertificate = 1;
                } else {
                    mHasCertificate = 0;
                }
            }
        });

        rgHasTrain.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbTrainYes) {
                    mHasTrain = 1;
                } else {
                    mHasTrain = 0;
                }
            }
        });

        rgHasFireStation.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbFireStationYes) {
                    mHasFireStation = 1;
                } else {
                    mHasFireStation = 0;
                }
            }
        });

        rgHasManage.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbManageYes) {
                    mHasManage = 1;
                } else {
                    mHasManage = 0;
                }
            }
        });

        rgHasMaintenanceUnit.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbMaintenanceUnitYes) {
                    mHasMaintenanceUnit = 1;
                } else if (checkedId == R.id.rbMaintenanceUnitNo) {
                    mHasMaintenanceUnit = 2;
                } else {
                    mHasMaintenanceUnit = 3;
                }
            }
        });

        rgHasDailyMaintenance.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbDailyMaintenanceYes) {
                    mHasDailyMaintenance = 1;
                } else {
                    mHasDailyMaintenance = 0;
                }
            }
        });

        rgHasGuardianship.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbGuardianshipYes) {
                    mHasGuardianship = 1;
                } else {
                    mHasGuardianship = 0;
                }
            }
        });

        rgHasRometeManage.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbRometeManageYes) {
                    mHasRometeManage = 1;
                } else {
                    mHasRometeManage = 0;
                }
            }
        });
    }


    public void getData() {
        HttpMethods.getInstance().getFireManageInfo(UserInfoUtil.getCurrentUserAccessToken(), build_id, 2)
                .subscribe(new SampleProgressObserver<FireManageBean>(this) {
                    @Override
                    public void onNext(FireManageBean bean) {
                        if (bean == null || "".equals(bean.getGson_null())) {
                            bean = new FireManageBean();
                            BaseCheck bc1 = new BaseCheck();
                            bc1.setIs_ok(0);
                            bc1.setProblem("");
                            bc1.setMeasures("");
                            bean.setResponse_is_implemented(bc1);
                            BaseCheck bc2 = new BaseCheck();
                            bc2.setIs_ok(0);
                            bc2.setProblem("");
                            bc2.setMeasures("");
                            bean.setSafety_response_clearly(bc2);
                            BaseCheck bc3 = new BaseCheck();
                            bc3.setIs_ok(0);
                            bc3.setProblem("");
                            bc3.setMeasures("");
                            bean.setUnit_safety_check(bc3);
                            BaseCheck bc4 = new BaseCheck();
                            bc4.setIs_ok(0);
                            bc4.setProblem("");
                            bc4.setMeasures("");
                            bean.setPipe_well_occupation(bc4);
                            BaseCheck bc5 = new BaseCheck();
                            bc5.setIs_ok(0);
                            bc5.setProblem("");
                            bc5.setMeasures("");
                            bean.setElectrical_wiring_equipment(bc5);
                            BaseCheck bc6 = new BaseCheck();
                            bc6.setIs_ok(0);
                            bc6.setProblem("");
                            bc6.setMeasures("");
                            bean.setViolate_rules_rescue(bc6);
                            BaseCheck bc7 = new BaseCheck();
                            bc7.setIs_ok(0);
                            bc7.setProblem("");
                            bc7.setMeasures("");
                            bean.setControl_personnel_certificate(bc7);
                            BaseCheck bc8 = new BaseCheck();
                            bc8.setIs_ok(0);
                            bc8.setProblem("");
                            bc8.setMeasures("");
                            bean.setSafety_training_drill(bc8);
                            BaseCheck bc9 = new BaseCheck();
                            bc9.setIs_ok(1);
                            bc9.setProblem("");
                            bc9.setMeasures("");
                            bean.setBuilds_fire_station(bc9);
                            BaseCheck bc10 = new BaseCheck();
                            bc10.setIs_ok(0);
                            bc10.setProblem("");
                            bc10.setMeasures("");
                            bean.setElectrical_gas_maintenance(bc10);
                            BaseCheck bc11 = new BaseCheck();
                            bc11.setIs_ok(0);
                            bc11.setProblem("");
                            bc11.setMeasures("");
                            bean.setImplement_monitoring_safety(bc11);
                            BaseCheck bc12 = new BaseCheck();
                            bc12.setIs_ok(0);
                            bc12.setProblem("");
                            bc12.setMeasures("");
                            bean.setCombine_local_smart(bc12);
                            bean.setWb_com("");
                            bean.setNo_edit(1);
                        }

                        fillData(bean);
                    }
                });
    }

    private void fillData(FireManageBean bean) {
        if (bean.getResponse_is_implemented().getIs_ok() == 1) {
            rbDutyYes.setChecked(true);
        }

        etDutyProblem.setText(bean.getResponse_is_implemented().getProblem());
        etDutyMeasure.setText(bean.getResponse_is_implemented().getMeasures());

        if (bean.getSafety_response_clearly().getIs_ok() == 1) {
            rbEachDutyYes.setChecked(true);
        }

        etEachDutyProblem.setText(bean.getSafety_response_clearly().getProblem());
        etEachDutyMeasure.setText(bean.getSafety_response_clearly().getMeasures());

        if (bean.getUnit_safety_check().getIs_ok() == 1) {
            rbSafeCheckYes.setChecked(true);
        }

        etSafeCheckProblem.setText(bean.getUnit_safety_check().getProblem());
        etSafeCheckMeasure.setText(bean.getUnit_safety_check().getMeasures());

        if (bean.getPipe_well_occupation().getIs_ok() == 1) {
            rbDoorIsViolationYes.setChecked(true);
        }

        etDoorIsViolationProblem.setText(bean.getPipe_well_occupation().getProblem());
        etDoorIsViolationMeasure.setText(bean.getPipe_well_occupation().getMeasures());

        if (bean.getElectrical_wiring_equipment().getIs_ok() == 1) {
            rbCertificateYes.setChecked(true);
        }

        etCertificateProblem.setText(bean.getElectrical_wiring_equipment().getProblem());
        etCertificateMeasure.setText(bean.getElectrical_wiring_equipment().getMeasures());

        if (bean.getViolate_rules_rescue().getIs_ok() == 1) {
            rbTrainYes.setChecked(true);
        }

        etTrainProblem.setText(bean.getViolate_rules_rescue().getProblem());
        etTrainMeasure.setText(bean.getViolate_rules_rescue().getMeasures());

        if (bean.getControl_personnel_certificate().getIs_ok() == 1) {
            rbFireStationYes.setChecked(true);
        }

        etFireStationProblem.setText(bean.getControl_personnel_certificate().getProblem());
        etFireStationMeasure.setText(bean.getControl_personnel_certificate().getMeasures());

        if (bean.getSafety_training_drill().getIs_ok() == 1) {
            rbManageYes.setChecked(true);
        }

        etManageProblem.setText(bean.getSafety_training_drill().getProblem());
        etManageMeasure.setText(bean.getSafety_training_drill().getMeasures());

        if (bean.getBuilds_fire_station().getIs_ok() == 1) {
            rbMaintenanceUnitYes.setChecked(true);
        } else if (bean.getBuilds_fire_station().getIs_ok() == 2) {
            rbMaintenanceUnitNo.setChecked(true);
        } else {
            rbMaintenanceUnitNoInvolving.setChecked(true);
        }
        etMaintenanceUnit.setText(bean.getWb_com());
        etMaintenanceUnitProblem.setText(bean.getBuilds_fire_station().getProblem());
        etMaintenanceUnitMeasure.setText(bean.getBuilds_fire_station().getMeasures());

        if (bean.getElectrical_gas_maintenance().getIs_ok() == 1) {
            rbDailyMaintenanceYes.setChecked(true);
        }

        etDailyMaintenanceProblem.setText(bean.getElectrical_gas_maintenance().getProblem());
        etDailyMaintenanceMeasure.setText(bean.getElectrical_gas_maintenance().getMeasures());

        if (bean.getImplement_monitoring_safety().getIs_ok() == 1) {
            rbGuardianshipYes.setChecked(true);
        }

        etGuardianshipProblem.setText(bean.getImplement_monitoring_safety().getProblem());
        etGuardianshipMeasure.setText(bean.getImplement_monitoring_safety().getMeasures());

        if (bean.getCombine_local_smart().getIs_ok() == 1) {
            rbRometeManageYes.setChecked(true);
        }

        etRometeManageProblem.setText(bean.getCombine_local_smart().getProblem());
        etRometeManageMeasure.setText(bean.getCombine_local_smart().getMeasures());

        if (bean.getNo_edit() == 1) {
            tvSearch.setVisibility(View.VISIBLE);
        } else {
            tvSearch.setVisibility(View.INVISIBLE);
        }

        initGridViewList(bean);
    }

    void initGridViewList(FireManageBean fireManageBean) {
        List<SingleImageBean> singleImageBeans = new ArrayList<SingleImageBean>();

        SingleImageBean s1 = new SingleImageBean();
        s1.setPosition(0);
        s1.setDelModel(false);
        s1.setGridView(gvDuty);
        s1.setImageList(fireManageBean.getResponse_is_implemented().getImage());
        singleImageBeans.add(s1);

        SingleImageBean s2 = new SingleImageBean();
        s2.setPosition(1);
        s2.setDelModel(false);
        s2.setGridView(gvEachDuty);
        s2.setImageList(fireManageBean.getSafety_response_clearly().getImage());
        singleImageBeans.add(s2);

        SingleImageBean s3 = new SingleImageBean();
        s3.setPosition(2);
        s3.setDelModel(false);
        s3.setGridView(gvSafeCheck);
        s3.setImageList(fireManageBean.getUnit_safety_check().getImage());
        singleImageBeans.add(s3);

        SingleImageBean s4 = new SingleImageBean();
        s4.setPosition(3);
        s4.setDelModel(false);
        s4.setGridView(gvDoorIsViolation);
        s4.setImageList(fireManageBean.getPipe_well_occupation().getImage());
        singleImageBeans.add(s4);

        SingleImageBean s5 = new SingleImageBean();
        s5.setPosition(4);
        s5.setDelModel(false);
        s5.setGridView(gvCertificate);
        s5.setImageList(fireManageBean.getElectrical_wiring_equipment().getImage());
        singleImageBeans.add(s5);

        SingleImageBean s6 = new SingleImageBean();
        s6.setPosition(5);
        s6.setDelModel(false);
        s6.setGridView(gvTrain);
        s6.setImageList(fireManageBean.getViolate_rules_rescue().getImage());
        singleImageBeans.add(s6);

        SingleImageBean s7 = new SingleImageBean();
        s7.setPosition(6);
        s7.setDelModel(false);
        s7.setGridView(gvFireStation);
        s7.setImageList(fireManageBean.getControl_personnel_certificate().getImage());
        singleImageBeans.add(s7);

        SingleImageBean s8 = new SingleImageBean();
        s8.setPosition(7);
        s8.setDelModel(false);
        s8.setGridView(gvManage);
        s8.setImageList(fireManageBean.getSafety_training_drill().getImage());
        singleImageBeans.add(s8);

        SingleImageBean s9 = new SingleImageBean();
        s9.setPosition(8);
        s9.setDelModel(false);
        s9.setGridView(gvMaintenanceUnit);
        s9.setImageList(fireManageBean.getBuilds_fire_station().getImage());
        singleImageBeans.add(s9);

        SingleImageBean s10 = new SingleImageBean();
        s10.setPosition(9);
        s10.setDelModel(false);
        s10.setGridView(gvDailyMaintenance);
        s10.setImageList(fireManageBean.getElectrical_gas_maintenance().getImage());
        singleImageBeans.add(s10);

        SingleImageBean s11 = new SingleImageBean();
        s11.setPosition(10);
        s11.setDelModel(false);
        s11.setGridView(gvGuardianship);
        s11.setImageList(fireManageBean.getImplement_monitoring_safety().getImage());
        singleImageBeans.add(s11);

        SingleImageBean s12 = new SingleImageBean();
        s12.setPosition(11);
        s12.setDelModel(false);
        s12.setGridView(gvRometeManage);
        s12.setImageList(fireManageBean.getCombine_local_smart().getImage());
        singleImageBeans.add(s12);

        mulGridViewBean.setSingleImageList(singleImageBeans);
        refreshAdapter();
    }

    private void doPost() {
        Map<String, String> a1 = new HashMap<>();
        a1.put("is_ok", mDutyIsOK + "");
        a1.put("problem", etDutyProblem.getText().toString());
        a1.put("measures", etDutyMeasure.getText().toString());

        Map<String, String> a2 = new HashMap<>();
        a2.put("is_ok", mEachDutyIsOK + "");
        a2.put("problem", etEachDutyProblem.getText().toString());
        a2.put("measures", etEachDutyMeasure.getText().toString());

        Map<String, String> a3 = new HashMap<>();
        a3.put("is_ok", mSafeCheckIsOK + "");
        a3.put("problem", etSafeCheckProblem.getText().toString());
        a3.put("measures", etSafeCheckMeasure.getText().toString());

        Map<String, String> a4 = new HashMap<>();
        a4.put("is_ok", mDoorIsViolation + "");
        a4.put("problem", etDoorIsViolationProblem.getText().toString());
        a4.put("measures", etDoorIsViolationMeasure.getText().toString());

        Map<String, String> a5 = new HashMap<>();
        a5.put("is_ok", mHasCertificate + "");
        a5.put("problem", etCertificateProblem.getText().toString());
        a5.put("measures", etCertificateMeasure.getText().toString());

        Map<String, String> a6 = new HashMap<>();
        a6.put("is_ok", mHasTrain + "");
        a6.put("problem", etTrainProblem.getText().toString());
        a6.put("measures", etTrainMeasure.getText().toString());

        Map<String, String> a7 = new HashMap<>();
        a7.put("is_ok", mHasFireStation + "");
        a7.put("problem", etFireStationProblem.getText().toString());
        a7.put("measures", etFireStationMeasure.getText().toString());

        Map<String, String> a8 = new HashMap<>();
        a8.put("is_ok", mHasManage + "");
        a8.put("problem", etManageProblem.getText().toString());
        a8.put("measures", etManageMeasure.getText().toString());

        Map<String, String> a9 = new HashMap<>();
        a9.put("is_ok", mHasMaintenanceUnit + "");
        a9.put("problem", etMaintenanceUnitProblem.getText().toString());
        a9.put("measures", etMaintenanceUnitMeasure.getText().toString());

        Map<String, String> a10 = new HashMap<>();
        a10.put("is_ok", mHasDailyMaintenance + "");
        a10.put("problem", etDailyMaintenanceProblem.getText().toString());
        a10.put("measures", etDailyMaintenanceMeasure.getText().toString());

        Map<String, String> a11 = new HashMap<>();
        a11.put("is_ok", mHasGuardianship + "");
        a11.put("problem", etGuardianshipProblem.getText().toString());
        a11.put("measures", etGuardianshipMeasure.getText().toString());

        Map<String, String> a12 = new HashMap<>();
        a12.put("is_ok", mHasRometeManage + "");
        a12.put("problem", etRometeManageProblem.getText().toString());
        a12.put("measures", etRometeManageMeasure.getText().toString());

        Map<String, Map<String, String>> dataParams = new HashMap<>();
        dataParams.put("response_is_implemented", a1);
        dataParams.put("safety_response_clearly", a2);
        dataParams.put("unit_safety_check", a3);
        dataParams.put("pipe_well_occupation", a4);

        dataParams.put("electrical_wiring_equipment", a5);
        dataParams.put("violate_rules_rescue", a6);
        dataParams.put("control_personnel_certificate", a7);
        dataParams.put("safety_training_drill", a8);

        dataParams.put("builds_fire_station", a9);
        dataParams.put("electrical_gas_maintenance", a10);
        dataParams.put("implement_monitoring_safety", a11);
        dataParams.put("combine_local_smart", a12);


        MultipartBody.Builder builder = new MultipartBody.Builder();

        putBody(builder, AppConfig.ACCESS_TOKEN, AppMediaType.TEXT, UserInfoUtil.getCurrentUserAccessToken());
        putBody(builder, "build_id", AppMediaType.TEXT, build_id);
        putBody(builder, "type", AppMediaType.TEXT, 1 + "");
        putBody(builder, "data", AppMediaType.TEXT, new Gson().toJson(dataParams));
        putBody(builder, "action_type", AppMediaType.TEXT, "fire_safety_management");


        // 图片数组
        File file;
        int size = mulGridViewBean.getSingleImageList().size();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < mulGridViewBean.getSingleImageList().get(i).getImageList().size(); j++) {
                if (mulGridViewBean.getSingleImageList().get(i).getImageList().get(j).contains("http")) {
                    Log.e("ttt     ", mulGridViewBean.getSingleImageList().get(i).getImageList().get(j) + "\n");
                    continue;
                }
                else
                {
                    file = new File(mulGridViewBean.getSingleImageList().get(i).getImageList().get(j));
                    if (i ==0)
                    {
                        putBody(builder, "image*response_is_implemented[]", AppMediaType.JPG, file);
                    }
                    else if (i ==1)
                    {
                        putBody(builder, "image*safety_response_clearly[]", AppMediaType.JPG, file);
                    }
                    else if (i ==2)
                    {
                        putBody(builder, "image*unit_safety_check[]", AppMediaType.JPG, file);
                    }
                    else if (i ==3)
                    {
                        putBody(builder, "image*pipe_well_occupation[]", AppMediaType.JPG, file);
                    }
                    else if (i ==4)
                    {
                        putBody(builder, "image*electrical_wiring_equipment[]", AppMediaType.JPG, file);
                    }
                    else if (i ==5)
                    {
                        putBody(builder, "image*violate_rules_rescue[]", AppMediaType.JPG, file);
                    }
                    else if (i ==6)
                    {
                        putBody(builder, "image*control_personnel_certificate[]", AppMediaType.JPG, file);
                    }
                    else if (i ==7)
                    {
                        putBody(builder, "image*safety_training_drill[]", AppMediaType.JPG, file);
                    }
                    else if (i ==8)
                    {
                        putBody(builder, "image*builds_fire_station[]", AppMediaType.JPG, file);
                    }
                    else if (i ==9)
                    {
                        putBody(builder, "image*electrical_gas_maintenance[]", AppMediaType.JPG, file);
                    }
                    else if (i ==10)
                    {
                        putBody(builder, "image*implement_monitoring_safety[]", AppMediaType.JPG, file);
                    }
                    else if (i ==11)
                    {
                        putBody(builder, "image*combine_local_smart[]", AppMediaType.JPG, file);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }

        builder.setType(MultipartBody.FORM);
        MultipartBody multipartBody = builder.build();

        HttpMethods.getInstance().postFireManageInfo(multipartBody)
                .subscribe(new SampleProgressObserver<FireManageBean>(this) {
                    @Override
                    public void onNext(FireManageBean fireManageBean) {
                        ToastUtil.getInstances().showMsg("保存成功");
                    }
                });
    }

    @OnClick({R.id.tvBack, R.id.tvSearch})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvBack:
                finish();
                break;
            case R.id.tvSearch:
                downloadImage();
                break;
            default:
                break;
        }
    }

    @Override
    public void post() {
        doPost();
    }
}
